package controller;

import java.io.IOException;
import java.text.SimpleDateFormat;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.EmployeeDTO;
import model.LeaveDTO;
import model.LeaveTypeDTO;
import model.LedgerDTO;
import bizlogic.CalculateLeaveDays;

/**
 * Servlet implementation class Servlet222
 */
@WebServlet("/Servlet222")
public class Servlet222 extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public Servlet222() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		LeaveDTO leDTO = new LeaveDTO();
		EmployeeDTO empDTO=new EmployeeDTO();
		LeaveTypeDTO ltDTO = new LeaveTypeDTO();
		LedgerDTO ldDTO = new LedgerDTO();
		HttpSession session = request.getSession();
		
		SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");  		
		EmployeeDTO empsession=(EmployeeDTO)session.getAttribute("user");
		sdf.setLenient(false);
		
			
		
		
		leDTO.setReason(request.getParameter("comment"));
		leDTO.setWorkdissmenition(Integer.parseInt(request.getParameter("workdissemination")));
		leDTO.setContactDetail(request.getParameter("contactdetail"));
		//leDTO.setLeaveTypeID(Integer.parseInt(request.getParameter("type")));
		
		double remain;
		if (Integer.parseInt(request.getParameter("leavetype")) == "Annual") {
			leDTO.setLeaveTypeID(1);
			remain = (double) ldDTO.getRemainAnnualLeave();
			ldDTO.setRemainAnnualLeave((int)remain);
		}

		if (Integer.parseInt(request.getParameter("leavetype")) == "Medical") {
			leDTO.setLeaveTypeID(2);
			remain = (double) ldDTO.getRemainMedicalLeave();
			ldDTO.setRemainMedicalLeave((int)remain);
		}

		if (Integer.parseInt(request.getParameter("leavetype")) == "Compensation") {
			leDTO.setLeaveTypeID(3);
			remain = ldDTO.getRemainOverTimeHr();
			ldDTO.setRemainOverTimeHr(remain);
		}
		
		leDTO.setStartDate(request.getParameter("startdate"));
		leDTO.setEndDate(request.getParameter("enddate"));
		leDTO.setLeavePeriod(request.getParameter("leaveperiod"));
		
		
	}

}
